package com.qztech.sdk.base;

import android.os.Bundle;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
import android.view.View;

import org.greenrobot.eventbus.EventBus;



public abstract class BaseActivity extends AppCompatActivity {
    protected LoadingDialog mLoadingDialog;

    public abstract boolean hasRegisterEventBus();

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        if (hasRegisterEventBus()) {
            EventBus.getDefault().register(this);
        }
    }

    @Override
    public void setContentView(View view) {
        super.setContentView(view);
       // ButterKnife.bind(this);
    }

    @Override
    public void setContentView(int layoutResID) {
        super.setContentView(layoutResID);
       // ButterKnife.bind(this);
    }

    @Override
    protected void onDestroy() {
        dismissLoading();
        if (hasRegisterEventBus()) {
            EventBus.getDefault().unregister(this);
        }
        super.onDestroy();
    }

    protected void showLoadingDialog(String msg) {
        showLoadingDialog(msg, true);
    }

    protected void showLoadingDialog(String msg, boolean isCancelable) {
        if (mLoadingDialog == null) {
            mLoadingDialog = new LoadingDialog(this);
        }
        mLoadingDialog.setMessage(msg);
        mLoadingDialog.setCancelable(isCancelable);
        mLoadingDialog.setCanceledOnTouchOutside(isCancelable);
        mLoadingDialog.showLoading();
    }

    protected void dismissLoading() {
        if (mLoadingDialog != null && mLoadingDialog.isShowing()) {
            mLoadingDialog.dismiss();
        }
    }
}
